﻿using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;

namespace PowerWaveAddin
{
    /// <summary>
    /// Allows for logical sorting of file names.
    /// We have to do this so that slide 10 doesn'r get inserted
    /// between slides 1 and 2.
    /// </summary>
    class FileInfoLogicalComparer : IComparer
    {
        [DllImport("shlwapi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
        private static extern int StrCmpLogicalW(string strA, string strB);

        /// <summary>
        /// Does the comparison.  Imputs must be File Infos
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        int IComparer.Compare(object x, object y)
        {
            FileInfo fx = (FileInfo)x;
            FileInfo fy = (FileInfo)y;

            return StrCmpLogicalW(fx.Name, fy.Name);
        }
    }

    class StringLogicalComparer : IComparer
    {
        [DllImport("shlwapi.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
        private static extern int StrCmpLogicalW(string strA, string strB);

        /// <summary>
        /// Does the comparison.  Imputs must be strings
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        int IComparer.Compare(object x, object y)
        {
            string fx = (string)x;
            string fy = (string)y;

            return StrCmpLogicalW(fx, fy);
        }
    }
}
